package plsqlfs;

import java.sql.SQLException;

import com.google.common.annotations.VisibleForTesting;

import oracle.sql.ARRAY;

/**
 * Exposes all methods of {@link PlSqlFileSystem} as static methods instead of
 * instance methods to accommodate Oracle's requirement that all Java stored
 * procedures must reference static methods.
 * 
 * @author Adam Paynter
 * 
 */
public class StaticPlSqlFileSystem {

	@VisibleForTesting
	protected static PlSqlFileSystem instance;

	public static PlSqlFileSystem getInstance() throws SQLException {
		if (instance == null) {
			instance = new PlSqlFileSystem( new FileSystem() );
		}
		return instance;
	}

	public static String getVarcharTableTypeName() throws Exception {
		return getInstance().getVarcharTableTypeName();
	}

	public void setVarcharTableTypeName(String varcharTableTypeName) throws Exception {
		getInstance().setVarcharTableTypeName(varcharTableTypeName);
	}

	public static String getErrorTypeName() throws Exception {
		return getInstance().getErrorTypeName();
	}

	public void setErrorTypeName(String errorTypeName) throws Exception {
		getInstance().setErrorTypeName(errorTypeName);
	}

	public static String getFileHandleTypeName() throws Exception {
		return getInstance().getFileHandleTypeName();
	}

	public void setFileHandleTypeName(String fileHandleTypeName) throws Exception {
		getInstance().setFileHandleTypeName(fileHandleTypeName);
	}

	public static int appendToPath(String basePath, String relativePath, String[] newPath, FileSystemException[] error) throws Exception {
		return getInstance().appendToPath(basePath, relativePath, newPath, error);
	}

	public static int resolvePath(String path, String[] resolvedPath, FileSystemException[] error) throws Exception {
		return getInstance().getResolvedPath(path, resolvedPath, error);
	}

	public static int absolutePath(String path, String[] absolutePath, FileSystemException[] error) throws Exception {
		return getInstance().absolutePath(path, absolutePath, error);
	}

	public static int canonicalPath(String path, String[] canonicalPath, FileSystemException[] error) throws Exception {
		return getInstance().canonicalPath(path, canonicalPath, error);
	}

	public static int resolveFilePath(String filePath, String[] resolvedFilePath, FileSystemException[] error) throws Exception {
		return getInstance().getResolvedFilePath(filePath, resolvedFilePath, error);
	}

	public static int absoluteFilePath(String filePath, String[] absoluteFilePath, FileSystemException[] error) throws Exception {
		return getInstance().absoluteFilePath(filePath, absoluteFilePath, error);
	}

	public static int canonicalFilePath(String filePath, String[] canonicalFilePath, FileSystemException[] error) throws Exception {
		return getInstance().canonicalFilePath(filePath, canonicalFilePath, error);
	}

	public static int resolveDirectoryPath(String directoryPath, String[] resolvedDirectoryPath, FileSystemException[] error) throws Exception {
		return getInstance().getResolvedDirectoryPath(directoryPath, resolvedDirectoryPath, error);
	}

	public static int absoluteDirectoryPath(String directoryPath, String[] absoluteDirectoryPath, FileSystemException[] error) throws Exception {
		return getInstance().absoluteDirectoryPath(directoryPath, absoluteDirectoryPath, error);
	}

	public static int canonicalDirectoryPath(String directoryPath, String[] canonicalDirectoryPath, FileSystemException[] error) throws Exception {
		return getInstance().canonicalDirectoryPath(directoryPath, canonicalDirectoryPath, error);
	}

	public static int name(String path, String[] name, FileSystemException[] error) throws Exception {
		return getInstance().name(path, name, error);
	}

	public static int base(String name, String[] base, FileSystemException[] error) throws Exception {
		return getInstance().base(name, base, error);
	}

	public static int extension(String name, String[] extension, FileSystemException[] error) throws Exception {
		return getInstance().extension(name, extension, error);
	}

	public static int fileName(String filePath, String[] fileName, FileSystemException[] error) throws Exception {
		return getInstance().fileName(filePath, fileName, error);
	}

	public static int directoryName(String directoryPath, String[] directoryName, FileSystemException[] error) throws Exception {
		return getInstance().directoryName(directoryPath, directoryName, error);
	}

	public static int fileSize(String path, long[] fileSize, FileSystemException[] error) throws Exception {
		return getInstance().fileSize(path, fileSize, error);
	}

	public static int exists(String path, int[] exists, FileSystemException[] error) throws Exception {
		return getInstance().exists(path, exists, error);
	}

	public static int fileExists(String filePath, int[] exists, FileSystemException[] error) throws Exception {
		return getInstance().fileExists(filePath, exists, error);
	}

	public static int delete(String path, FileSystemException[] error) throws Exception {
		return getInstance().delete(path, error);
	}

	public static int isAbsolute(String path, int[] isAbsolute, FileSystemException[] error) throws Exception {
		return getInstance().isAbsolute(path, isAbsolute, error);
	}

	public static int isDirectory(String path, int[] isDirectory, FileSystemException[] error) throws Exception {
		return getInstance().isDirectory(path, isDirectory, error);
	}

	public static int isFile(String path, int[] isFile, FileSystemException[] error) throws Exception {
		return getInstance().isFile(path, isFile, error);
	}

	public static int touch(String path, FileSystemException[] error) throws Exception {
		return getInstance().touch(path, error);
	}

	public static int touchFile(String filePath, FileSystemException[] error) throws Exception {
		return getInstance().touchFile(filePath, error);
	}

	public static int touchDirectory(String directoryPath, FileSystemException[] error) throws Exception {
		return getInstance().touchDirectory(directoryPath, error);
	}

	public static int listNames(String directoryPath, ARRAY[] names, FileSystemException[] error) throws Exception {
		return getInstance().listNames(directoryPath, names, error);
	}

	public static int listNames(String directoryPath, String pattern, ARRAY[] names, FileSystemException[] error) throws Exception {
		return getInstance().listNames(directoryPath, pattern, names, error);
	}

	public static int listPaths(String directoryPath, ARRAY[] paths, FileSystemException[] error) throws Exception {
		return getInstance().listPaths(directoryPath, paths, error);
	}

	public static int listPaths(String directoryPath, String pattern, ARRAY[] paths, FileSystemException[] error) throws Exception {
		return getInstance().listPaths(directoryPath, pattern, paths, error);
	}

	public static int listFileNames(String directoryPath, ARRAY[] fileNames, FileSystemException[] error) throws Exception {
		return getInstance().listFileNames(directoryPath, fileNames, error);
	}

	public static int listFileNames(String directoryPath, String pattern, ARRAY[] fileNames, FileSystemException[] error) throws Exception {
		return getInstance().listFileNames(directoryPath, pattern, fileNames, error);
	}

	public static int listFilePaths(String directoryPath, ARRAY[] filePaths, FileSystemException[] error) throws Exception {
		return getInstance().listFilePaths(directoryPath, filePaths, error);
	}

	public static int listFilePaths(String directoryPath, String pattern, ARRAY[] filePaths, FileSystemException[] error) throws Exception {
		return getInstance().listFilePaths(directoryPath, pattern, filePaths, error);
	}

	public static int listDirectoryNames(String directoryPath, ARRAY[] fileNames, FileSystemException[] error) throws Exception {
		return getInstance().listDirectoryNames(directoryPath, fileNames, error);
	}

	public static int listDirectoryNames(String directoryPath, String pattern, ARRAY[] fileNames, FileSystemException[] error) throws Exception {
		return getInstance().listDirectoryNames(directoryPath, pattern, fileNames, error);
	}

	public static int listDirectoryPaths(String directoryPath, ARRAY[] filePaths, FileSystemException[] error) throws Exception {
		return getInstance().listDirectoryPaths(directoryPath, filePaths, error);
	}

	public static int listDirectoryPaths(String directoryPath, String pattern, ARRAY[] filePaths, FileSystemException[] error) throws Exception {
		return getInstance().listDirectoryPaths(directoryPath, pattern, filePaths, error);
	}

	public static int listRootDirectoryPaths(ARRAY[] rootDirectoryPaths, FileSystemException[] error) throws Exception {
		return getInstance().listRootDirectoryPaths(rootDirectoryPaths, error);
	}

	public static int copyFileToFile(String sourceFilePath, String destinationFilePath, FileSystemException[] error) throws Exception {
		return getInstance().copyFileToFile(sourceFilePath, destinationFilePath, error);
	}

	public static int copyFileToDirectory(String sourceFilePath, String destinationDirectoryPath, String[] destinationFilePath, FileSystemException[] error) throws Exception {
		return getInstance().copyFileToDirectory(sourceFilePath, destinationDirectoryPath, destinationFilePath, error);
	}

	public static int moveFileToFile(String sourceFilePath, String destinationFilePath, FileSystemException[] error) throws Exception {
		return getInstance().moveFileToFile(sourceFilePath, destinationFilePath, error);
	}

	public static int moveFileToDirectory(String sourceFilePath, String destinationDirectoryPath, String[] destinationFilePath, FileSystemException[] error) throws Exception {
		return getInstance().moveFileToDirectory(sourceFilePath, destinationDirectoryPath, destinationFilePath, error);
	}

	public static int openBinaryFileForReading(String filePath, int bufferSize, FileHandle[] fileHandle, FileSystemException[] error) throws Exception {
		return getInstance().openBinaryFileForReading(filePath, bufferSize, fileHandle, error);
	}

	public static int openBinaryFileForWriting(String filePath, int bufferSize, FileHandle[] fileHandle, FileSystemException[] error) throws Exception {
		return getInstance().openBinaryFileForWriting(filePath, bufferSize, fileHandle, error);
	}

	public static int openTextualFileForReading(String filePath, String charsetName, int bufferSize, FileHandle[] fileHandle, FileSystemException[] error) throws Exception {
		return getInstance().openTextualFileForReading(filePath, charsetName, bufferSize, fileHandle, error);
	}

	public static int openTextualFileForWriting(String filePath, String charsetName, int bufferSize, FileHandle[] fileHandle, FileSystemException[] error) throws Exception {
		return getInstance().openTextualFileForWriting(filePath, charsetName, bufferSize, fileHandle, error);
	}

	public static int closeFileHandle(FileHandle fileHandle, FileSystemException[] error) throws Exception {
		return getInstance().closeFileHandle(fileHandle, error);
	}

	public static int hasMoreLines(FileHandle fileHandle, int[] result, FileSystemException[] error) throws Exception {
		return getInstance().hasMoreLines(fileHandle, result, error);
	}

	public static int readLine(FileHandle fileHandle, String[] line, FileSystemException[] error) throws Exception {
		return getInstance().readLine(fileHandle, line, error);
	}

	public static int readLines(String filePath, String charsetName, ARRAY[] lines, FileSystemException[] error) throws Exception {
		return getInstance().readLines(filePath, charsetName, lines, error);
	}

	public static int write(FileHandle fileHandle, String text, FileSystemException[] error) throws Exception {
		return getInstance().write(fileHandle, text, error);
	}

	public static int writeLine(FileHandle fileHandle, String text, FileSystemException[] error) throws Exception {
		return getInstance().writeLine(fileHandle, text, error);
	}

}
